package cn.edu.sgu.www.pms.restful;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 分页查询结果对象
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Data
@ApiModel
public class JsonPage<T> implements Serializable {
    private static final long serialVersionUID = 18L;

    /**
     * 总记录数
     */
    @ApiModelProperty(value = "总记录数", required = true)
    private Long total;

    /**
     * 查询结果
     */
    @ApiModelProperty(value = "查询结果", required = true)
    private List<T> rows;

    public static <T> JsonPage<T> restPage(Page<T> page) {
        JsonPage<T> jsonPage = new JsonPage<>();

        jsonPage.setTotal(page.getTotal());
        jsonPage.setRows(page.getRecords());

        return jsonPage;
    }

    public static <T> JsonPage<T> restPage(Long total, List<T> rows) {
        JsonPage<T> jsonPage = new JsonPage<>();

        jsonPage.setTotal(total);
        jsonPage.setRows(rows);

        return jsonPage;
    }

}